/**
 * Created by tsingwong on 16-6-29.
 */

var CometPolling = function () {
    return {
        init: function () {

            $.ajax({
                type: "get",
                dataType: "json",
                url: "http://192.168.109.29:8080/207Shared/GetNew",
                timeout: 1200000,
                success: function (data, status) {
                    console.log(data);
                    var obj,
                        student_html = "",
                        report_html = "",
                        $student = $("#student"),
                        $container = $('#report-content');


                    obj = eval(data);
                    console.log(obj);

                    index = num;
                    // generate the left list
                    student_html = '<a href="#section-' + (index + 1) + ' "> ' + obj['name'] + '</a>';
                    var $li = $("<li></li>");
                    $li.html(student_html);
                    $student.append($li);


                    // generate the right part
                    report_html = '<div class="page-header"><h2>' + obj['name'] + '第XX周周报 <small>' + obj['subject'] + '</small></h2></div><h3>本周工作总结</h3>'
                        + formatList(obj['summary'])
                        + '<h3>本周存在问题</h3>'
                        + formatList(obj['problem'])
                        + '<h3>下周工作计划</h3>'
                        + formatList(obj['goal']);

                    var $div_report = $("<section></section>");
                    $div_report.attr('id', 'section-' + (index + 1));
                    $div_report.html(report_html);
                    $container.append($div_report);

                    dm_notification('收到来自' + obj['name'] + '的新周报', 5000);

                    CometPolling.init();
                },
                error: function (err, status) {
                    console.log(status);
                    console.log(err);
                    if (status == "timeout") {
                        console.log("timeout");
                        CometPolling.init();
                    }

                }

            })
        }
    }
}();



